package com.fc.gateway.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

import java.util.Objects;

/**
 * @Description: 路由限流配置
 * @ClassName: RateLimiterConfiguration
 * @Author: weisn
 * @Date: 2022/12/16 15:50
 * @Version: 1.0
 */
@Configuration(proxyBeanMethods = false)
public class RateLimiterConfiguration {

    @Bean
    public KeyResolver remoteAddrKeyResolver() {
        return exchange -> Mono
                .just(Objects.requireNonNull(Objects.requireNonNull(exchange.getRequest().getRemoteAddress()))
                        .getAddress().getHostAddress());
    }
}
